package com.lwl.blue.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lwl.blue.commont.base.BizException;
import com.lwl.blue.commont.base.ErrorCode;
import com.lwl.blue.commont.base.JsonResult;
import com.lwl.blue.commont.base.PageParam;
import com.lwl.blue.dao.PurchaseOrderDetailDao;
import com.lwl.blue.entity.PurchaseOrderDetail;
import com.lwl.blue.service.PurchaseOrderDetailService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class PurchaseOrderDetailServiceImpl extends ServiceImpl<PurchaseOrderDetailDao, PurchaseOrderDetail> implements PurchaseOrderDetailService {

    @Resource
    private PurchaseOrderDetailDao purchaseOrderDetailDao;

    @Override
    public JsonResult<Page<PurchaseOrderDetail>> pages(PageParam<PurchaseOrderDetail> pageParam) {
        // 构建分页对象并调用自定义 Mapper 方法执行分页
        Page<PurchaseOrderDetail> page = new Page<>(pageParam.getPageNum(), pageParam.getPageSize());
        return new JsonResult<Page<PurchaseOrderDetail>>().success(purchaseOrderDetailDao.pages(page, pageParam.getParam()));
    }

    @Override
    public JsonResult<PurchaseOrderDetail> getByPk(Long id) {
        // 主键查询明细，未找到则抛出统一异常
        PurchaseOrderDetail pod = purchaseOrderDetailDao.getByPk(id);
        if (pod == null) {
            throw new BizException(ErrorCode.DATA_NOT_EXIST_ERROR.getCode(), ErrorCode.DATA_NOT_EXIST_ERROR.getMsg());
        }
        return new JsonResult<PurchaseOrderDetail>().success(pod);
    }
}


